<?php

function press_releases_validation($form) {

  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
  chkbadchar($form['field_press_number']['und'][0]['value']['#value'], $form['field_press_number']['und'][0]['value']['#title'], 'field_press_number');
  chkbadchar($form['field_press_details']['und'][0]['value']['#value'], $form['field_press_details']['und'][0]['value']['#title'], 'field_press_details');
  chkbadchar($form['field_press_photo_caption']['und'][0]['value']['#value'], $form['field_press_photo_caption']['und'][0]['value']['#title'], 'field_press_photo_caption');
  chkbadchar($form['field_press_keywords']['und'][0]['value']['#value'], $form['field_press_keywords']['und'][0]['value']['#title'], 'field_press_keywords');

  // Date Validation
    //check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');

	check_date_expire($form['field_press_date']['und'][0]['value']['date']['#value'],$form['field_press_date']['#title']);

  // maximum length validation for Title and Description Field
  	maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');

	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_press_keywords']['und'][0]['value']['#value'], 5, $form['field_press_keywords']['und'][0]['value']['#title'],'field_press_keywords');
	minilength_validation($form['field_press_details']['und'][0]['value']['#value'], 5, $form['field_press_details']['und'][0]['value']['#title'],'field_press_details');


//District field Check
distvalidation($form['field_press_district']['und']['#value']);


 // Availability of press release
if ($form['field_press_availability']['und']['#value'] == 'online') {
    url_validation($form['field_press_url']['und'][0]['value']['#value']);
}


 if ($form['field_press_availability']['und']['#value'] == '_none') {

	$filename = $form['field_press_photos']['und'][0]['#file'];
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_press_photos']['und']['#title']);

  }

	if ($form['field_press_availability']['und']['#value'] == 'download') {

		if($form['field_press_number']['und'][0]['value']['#value']==''){
		     form_set_error($field_name, t('Kindly choose the upload file '.$field_name.' field', array(
													   '%name' => $form['field_press_number']['und'][0]['value']['#value']['#title'])));
			 //form_set_error('field_press_number', t('If \'Availability of PressRelease\' is Downloadble, %name field is required', array(
													   //'%name' => $form['field_press_number']['und'][0]['value']['#value']['#title'])));
		}

		if($form['field_press_upload']['und'][0]['fid']['#value']=='0'){
		form_set_error('field_press_upload', t('If \'Availability of PressRelease\' is Downloadble, %name field is required', array(
													   '%name' => $form['field_press_upload']['und'][0]['fid']['#value']['#title'])));
		}
	}


	elseif ($form['field_press_availability']['und']['#value'] == ''){

		if($form['field_press_photos']['und'][0]['fid']['#value']=='0'){

			form_set_error('field_press_photos', t('Both \'Press Release Photos\' and  \'Avaialbility of press release\' cannot be empty. Atlease either one of the value should be Entered', array('%name' => $form['field_press_number'] ['und'][0]['value']['#value']['#title'])));
		}

	}

}





